
#ifndef __WN_UPDAE__H
#define __WN_UPDAE__H
#include <rtthread.h>
#include "wn_device.h"
#define SUBDEV_PACKAGE_LEN   (1024 * 600)
#define SUBDEV_PAGE_LEN      (126)
#define SUBDEV_PAGE_COUNT    (32)
#define SUBDEV_UPGRADE_COUNT (3)
#define SUBDEV_VERSION         (16)
#define HUBPACKETSIZE 200*1024

typedef enum
{
    SUBDEV_PAGE_RETURN_ERR  = 0,/*返回失败*/
    SUBDEV_PAGE_RETURN_OK,      /*返回成功*/
    SUBDEV_PAGE_RETURN_NONE     /*无返回*/
}SUBDEV_UP_PAGE_RESULT_E;

typedef enum 
{
    UPGRADE_IDLE=0,
    UPGRADE_WORK,
}Upgrade_Status_t;

typedef struct{
    Upgrade_Status_t status;
    int len; //升级包长度
    uint8_t data[HUBPACKETSIZE];
    int packetCount; //总包数
    int packetNo;   //发送第几包
    int data_index; // 当前发送位置
    uint8_t current_sn[WN_DEVICE_SN_MAX];

}UPGRADE_PACK;


int wn_update_process();
int wn_update_fromurl(const char* url);

int wn_load_fireware(const char *filename);
int wn_ota_init();
int wn_ota_start();
int wn_ota_stop();
int wn_ota_getprocess();

int wn_ota_upgrade(char*url,char* md5,sn_set_t*sns,int sn_size);
int wn_ota_upgrade_async(char*url,char* md5,sn_set_t*sns,int sn_size);
#endif
